package dao.impl;

import dao.FeedBackDao;
import entity.Feedback;
import util.DruidUtils;
import util.FeedBackRowMapper;

import java.util.List;

/**
 * @Auther:
 * @Date: 2020-05-12
 * @Description: @PACKAGE:dao.impl
 * @version: 1.0
 */
public class FeedBackDaoImpl implements FeedBackDao {

    @Override
    public List<Feedback> getAllFeedback() {
        String sql = "select * from t_feedback";
        List<Feedback> list = DruidUtils.commonsSelect(sql, new FeedBackRowMapper(), new Object[]{});
        return list;
    }

    @Override
    public List<Feedback> getAllShortByFrequency(String aORde) {
        String sql = "select * from t_feedback order by where f_frequency " + aORde;
        List<Feedback> list = DruidUtils.commonsSelect(sql, new FeedBackRowMapper(), new Object[]{});
        return list;
    }

    @Override
    public List<Feedback> getByDoctorName(String name) {
        String sql = "select * from t_feedback where doctor_name ='" + name + "' order by f_flag asc,f_date desc";
        List<Feedback> list = DruidUtils.commonsSelect(sql, new FeedBackRowMapper(), new Object[]{});
        return list;
    }

    @Override
    public List<Feedback> getByDoctorId(String id) {
        String sql = "select * from t_feedback where doctor_id ='" + id + "' order by f_flag asc,f_date desc";
        List<Feedback> list = DruidUtils.commonsSelect(sql, new FeedBackRowMapper(), new Object[]{});
        return list;
    }

    @Override
    public List<Feedback> getByFlag() {
        String sql = "select * from t_feedback where f_flag ='0' order by f_date asc";
        List<Feedback> list = DruidUtils.commonsSelect(sql, new FeedBackRowMapper(), new Object[]{});
        return list;
    }

    @Override
    public int add(Feedback feedback) {
        String sql = "insert  into `t_feedback` (`doctor_id`,`doctor_name`,`f_massage`,`f_date`,`f_frequency`,`f_flag`) values (?,?,?,?,?,?)";

        int i = DruidUtils.executeUpdate(sql, feedback.getDoctorId(), feedback.getDoctorName(), feedback.getfMassage(), feedback.getfDate(),
                feedback.getFrequency(), feedback.getFlag());

        return i;
    }

    @Override
    public int delete(String doctor) {
        return 0;
    }

    @Override
    public int update(Feedback tFeedback) {
        String sql = "update `t_feedback` set `doctor_id`=?,`doctor_name`=?,`f_massage`=?,`f_date`=?,`f_frequency`=?,`f_flag`=?, where `num`=?";

        int i = DruidUtils.executeUpdate(sql, tFeedback.getDoctorId(), tFeedback.getDoctorName(), tFeedback.getfMassage(),
                tFeedback.getfDate(), tFeedback.getFrequency(), tFeedback.getFlag(), tFeedback.getNum());

        return i;
    }

    @Override
    public int updateFlag(int num) {
        String sql = "update `t_feedback` set `f_flag`=1 where `num`=?";

        int i = DruidUtils.executeUpdate(sql, num);

        return i;
    }
}